package com.toe.admin.controller;

import com.toe.common.restful.JsonPage;
import com.toe.common.restful.JsonResult;
import com.toe.love.service.LoveGoodsService;
import com.toe.pojo.dto.love.LoveGoodInfoDTO;
import com.toe.pojo.vo.love.LoveGoodInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/love")
@Api(tags = "爱心商品模块")
public class LoveController {
    @DubboReference
    private LoveGoodsService loveGoodsService;

    @ApiOperation("上架爱心商品")
    @PostMapping("/add")
    public JsonResult<Void> addLoveGood(@RequestBody LoveGoodInfoDTO loveGoodInfoDTO) {
        loveGoodsService.addLoveGood(loveGoodInfoDTO);
        return JsonResult.ok();
    }

    @ApiOperation("分页查询爱心商品")
    @GetMapping("/page/{pageNum}/{pageSize}")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码", name = "pageNum",example = "1"),
            @ApiImplicitParam(value = "每页条数", name = "pageSize", example = "5")
    })
    public JsonResult<JsonPage<LoveGoodInfoVO>> pageLoveGoods(@PathVariable Integer pageNum, @PathVariable Integer pageSize) {
        JsonPage<LoveGoodInfoVO> jsonPage = loveGoodsService.pageLoveGoods(pageNum, pageSize);
        return JsonResult.ok(jsonPage);
    }

    @ApiOperation("下架爱心商品")
    @PostMapping("/delete/{id}")
    public JsonResult<Void> removeLoveGood(@PathVariable Long id) {
        loveGoodsService.removeLoveGood(id);
        return JsonResult.ok();
    }

}
